package com.ssy.lingxi.member.merchant.model.constant;

import com.ssy.lingxi.common.language.LanguageHolder;
import com.ssy.lingxi.member.merchant.model.vo.basic.response.DropdownItem;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 结算单据枚举
 * @author 万宁
 * @version 2.0.0
 * @date 2021-05-25
 */
public enum SettlementDocumentsEnum {

    /**
     * 结算单据枚举
     1、订单
     2、物流单
     3、生产通知单
     4、发货单
     5、收货单
     6、发票单
     7、收货单+发票单
     */

    /**
     * 1、订单
     */
    ORDER(1, "订单"),

    /**
     * 2、物流单
     */
    LOGISTICS_ORDER(2, "物流单"),

    /**
     * 3、生产通知单
     */
    PRODUCTION_NOTICE(3, "生产通知单"),

    /**
     * 4、发货单
     */
    INVOICE(4, "发货单"),

    /**
     * 5、收货单
     */
    RECEIPT(5, "收货单"),

    /**
     * 6、发票单
     */
    PROFORMA_INVOICE(6, "发票单"),

    /**
     * 7、收货单+发票单
     */
    RECEIPT_AND_PROFORMA_INVOICE(7, "收货单+发票单");

    SettlementDocumentsEnum(Integer code, String msg) {
        this.code = code;
    }

    private final Integer code;

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return LanguageHolder.getName(this.getClass(), this.getCode());
    }

    public static List<DropdownItem> toDropdownList() {
        List<DropdownItem> items = Arrays.stream(SettlementDocumentsEnum.values()).sorted(Comparator.comparingInt(SettlementDocumentsEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
        items.add(0 , new DropdownItem(0, MemberStringEnum.CHOOSE.getName()));
        return items;
    }

    public static List<DropdownItem> toEditableDropdownList() {
        return Arrays.stream(SettlementDocumentsEnum.values()).sorted(Comparator.comparingInt(SettlementDocumentsEnum::getCode)).map(e -> new DropdownItem(e.getCode(), e.getMsg())).collect(Collectors.toList());
    }

    public static String getCodeMsg(Integer code) {
        return LanguageHolder.getName(SettlementDocumentsEnum.class, code);
    }

    /**
     * 根据枚举值获得名称
     * @param code 枚举值
     * @return 发票名称
     */
    public static String getNameByCode(Integer code) {
        return LanguageHolder.getName(SettlementDocumentsEnum.class, code);
    }
}
